package com.example.wechat2

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView


class FriAdapter(val friendsInfos: ArrayList<FriendsFragment.FriendsInfo>) : RecyclerView.Adapter<FriAdapter.FriendsInfoViewHolder>() {

    inner class FriendsInfoViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val img=itemView.findViewById<ImageView>(R.id.fri_img_frihead)
        val name=itemView.findViewById<TextView>(R.id.fri_text_fri_name)
    }

    override fun onCreateViewHolder(
        parent: ViewGroup,
        viewType: Int
    ): FriendsInfoViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.item_friends, parent, false)
        val holder = FriendsInfoViewHolder(view)
        return holder
    }


    override fun onBindViewHolder(holder: FriendsInfoViewHolder, position: Int) {
       val obj=friendsInfos[position]
       holder.name.text = obj.fri_name
        holder.img.setImageResource(obj.fri_head)
    }

    override fun getItemCount(): Int {
        return friendsInfos.size
    }

}
